package com.badu.fx.api;

import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.badu.common.utils.R;
import com.badu.fx.service.IFxLevelRecordService;

/**
 * <p>
 * 分销级别关联表 前端控制器
 * </p>
 *
 * @author astupidcoder123
 * @since 2021-01-13
 */
@Validated
@RestController
@RequestMapping("api/fx/level/record")
public class FxLevelRecordApi {

	@Autowired
	private IFxLevelRecordService iFxLevelRecordService;
	
	/**
	 * 添加级别
	 * @param parentOpenId
	 * @param childOpenId
	 * @return
	 */
	@PostMapping("addLevelRecord")
	public R  addLevelRecord(@NotBlank(message = "parentOpenId必填") String parentOpenId 
			                ,@NotBlank(message = "childOpenId必填") String childOpenId) {
		return R.insertOrUpdateHandleResult(iFxLevelRecordService.addFxLevelRecord(parentOpenId, childOpenId));
	}
	
	/**
	 * 查询我的上级
	 * @param myOpenId
	 * @param level
	 * @return
	 */
	@GetMapping("queryMyParentLevelByMyOpenId")
	public R queryMyParentLevelByMyOpenId(@NotBlank(message = "myOpenId必填") String myOpenId,@RequestParam(defaultValue = "2",required = false,name ="level" )Integer level ) {
		return R.ok().put("data", iFxLevelRecordService.querySuperior(myOpenId, level));
	}
	
	/**
	 * 查询我的下级
	 * @param myOpenId
	 * @param level
	 * @return
	 */
	@GetMapping("queryMyLowerLevelByMyOpenId")
	public R queryMyLowerLevelByMyOpenId(@NotBlank(message = "myOpenId必填") String myOpenId,@RequestParam(defaultValue = "2",required = false,name ="level" )Integer level ) {
		return R.ok().put("data", iFxLevelRecordService.queryLowerLevel(myOpenId, level));
	}
	
	/**
	 * 查询我的上级 分组
	 * @param myOpenId
	 * @param level
	 * @return
	 */
	@GetMapping("queryMyParentLevelByMyOpenIdGroup")
	public R queryMyParentLevelByMyOpenIdGroup(@NotBlank(message = "myOpenId必填") String myOpenId,@RequestParam(defaultValue = "2",required = false,name ="level" )Integer level ) {
		return R.ok().put("data", iFxLevelRecordService.querySuperiorGroup(myOpenId, level));
	}
	
	/**
	 * 查询我的下级 分组
	 * @param myOpenId
	 * @param level
	 * @return
	 */
	@GetMapping("queryMyLowerLevelByMyOpenIdGroup")
	public R queryMyLowerLevelByMyOpenIdGroup(@NotBlank(message = "myOpenId必填") String myOpenId,@RequestParam(defaultValue = "2",required = false,name ="level" )Integer level ) {
		return R.ok().put("data", iFxLevelRecordService.queryLowerLevelGroup(myOpenId, level));
	}
}
